package com.yy.yycompnent.slide{
	import com.yy.tools.graphics.GT;
	
	import flash.display.*;
	import flash.events.*;
	
	public class SliderBar{
		
		private const LIST:Array = ["top", "bottom", "middle", "barLine"];
		
		private var _sliderBar:MovieClip = null;//滚动条滑块资源
		private var _isSelected:Boolean = false;
		private var _height:Number = 0;
		private var _y:Number = 0;
		private var _bottom:MovieClip = null;
		private var _top:MovieClip = null;
		private var _barLine:MovieClip = null;
		private var _visible:Boolean = false;
		private var _middle:MovieClip = null;
		
		public function SliderBar(view:MovieClip){
			_sliderBar = view;
			_sliderBar.buttonMode = true;
			_sliderBar.mouseChildren = false;
			_top = _sliderBar.top;
			_middle = _sliderBar.middle;
			_bottom = _sliderBar.bottom;
			_barLine = _sliderBar.barLine;
			showMouseEffect("out");
		}
		public function get y():Number{
			return _sliderBar.y;
		}
		public function select(boo:Boolean):void{
			_isSelected = boo;
			if (_isSelected){
				showMouseEffect("down");
				return;
			};
			showMouseEffect("out");
		}
		/**
		 *矫正滑块 坐标
		 * 
		 */
		private function adjustBar():void{
			_top.y = 0;
			_middle.y = (_top.y + _top.height);
			if (_barLine){
				_barLine.y = (_middle.y + ((_middle.height - _barLine.height) / 2));
			};
			_bottom.y = (_middle.y + _middle.height);
		}
		/**
		 *设置滑块的高 
		 * @param value
		 * 
		 */
		public function set height(value:Number):void{
			if (value > ((_top.height + _bottom.height) + 10)){
				_height = value;
			} else {
				_height = ((_top.height + _bottom.height) + 10);
			};
			_middle.height = ((_height - _top.height) - _bottom.height);
			adjustBar();
		}
		
		public function get width():Number{
			return 0;
		}
		public function set width(w:Number):void {
			
		}
		
		
		/**
		 *显示效果 
		 * @param label
		 * 
		 */
		private function showMouseEffect(label:String):void{
			var i:int;
			i = 0;
			while (i< LIST.length) {
				GT.stopMovieToLable(this[("_" + LIST[i])], label);
				i++;
			};
		}
		/**
		 *鼠标移开 
		 * @param e
		 * 
		 */
		private function outHandler(e:MouseEvent):void{
			if (_isSelected){
				return;
			};
			showMouseEffect("out");
		}
		/**
		 *显示滑块 
		 * 
		 */
		public function showBar():void{
			_sliderBar.visible = true;
			_visible = true;
			addEvent();
		}
		public function get visible():Boolean{
			return (_visible);
		}
		/**
		 *鼠标移动到滑块上 
		 * @param e
		 * 
		 */
		private function overHandler(e:MouseEvent):void{
			if (_isSelected){
				return;
			};
			showMouseEffect("over");
		}
		private function downHandler(e:MouseEvent):void {
			if(_isSelected) {
				return;
			}
			showMouseEffect("down");
		}
		/**
		 *获得滑块的高 
		 * @return 
		 * 
		 */
		public function get height():Number{
//			return (_top.height + _middle.height + _bottom.height);
			return _sliderBar.height;
		}
		
		/**
		 *隐藏滚动条 
		 * 
		 */
		public function hideBar():void{
			_sliderBar.visible = false;
			_visible = false;
			removeEvent();
		}
		public function set y(value:Number):void{
			_y = value;
			_sliderBar.y = _y;
		}
		public function get x():Number{
			return 0;
		}
		public function set x(value:Number):void{
			
		}
		private function removeEvent():void{
			_sliderBar.removeEventListener(MouseEvent.ROLL_OVER, overHandler);
			_sliderBar.removeEventListener(MouseEvent.ROLL_OUT, outHandler);
			_sliderBar.removeEventListener(MouseEvent.MOUSE_DOWN, downHandler);
		}
		private function addEvent():void{
			_sliderBar.addEventListener(MouseEvent.ROLL_OVER, overHandler);
			_sliderBar.addEventListener(MouseEvent.ROLL_OUT, outHandler);
			_sliderBar.addEventListener(MouseEvent.MOUSE_DOWN, downHandler);
		}

		public function get sliderBar():MovieClip
		{
			return _sliderBar;
		}
	}
}